package _0000_study._leetcode._swordoffer._010_Fibonacci_II;

/**
 * Date: 2021/9/4 13:
 * 执行用时：0 ms, 在所有 Java 提交中击败了100.00%的用户
 * 内存消耗：34.9 MB, 在所有 Java 提交中击败了97.10%的用户
 */
public class Solution {

    public static final int mod = (int) 1e9 + 7;

    public int fib(int n) {
        if (n <= 1) return n;

        int a = 0, b = 1, c = 0;
        for (int i = 0; i < n - 1; i++) {
            c = (a + b) % mod;
            a = b;
            b = c;
        }
        return c;
    }

    public static void main(String[] args) {

        System.out.println((new Solution()).fib(3));
    }
}
